/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.rockville.ufone;

import org.apache.log4j.Logger;

import com.rockville.httpRequest.HttpRequestUrl;

/**
 * 
 * @author M Bilal
 */
public class CricLiveScoreParser implements Runnable {

    private static final Logger log = Logger.getLogger(CricLiveScoreParser.class);
    private static final String liveScoreURL = "http://sms.cricbuzz.com/rockville/rockville-score.txt";
	DBProc dbp = DBProc.getInstance();
    
    public CricLiveScoreParser() {
    }

    public void run() {
        log.debug("*****CricLiveScoreParser Started*****");
        try {
        	String liveScore = HttpRequestUrl.getURLResponse(liveScoreURL);
//        	int i = 0;
        	String teamA = "";
        	String teamB = "";
//        	if((i=liveScore.indexOf(",")) > -1) {
//        		String match = liveScore.substring(0, i);
//        		log.debug("live score for match: "+match);
//        		int ti = -1;
//        		if((ti=match.indexOf(" v ")) > -1) {
//        			teamA = match.substring(0, ti);
//        			teamB = match.substring(ti+3);
//        		}
//        		liveScore = liveScore.substring(i+1).trim();
//        		liveScore = liveScore.replaceAll("Group B: ", "Group B:<br/>");
//        		liveScore = liveScore.replaceAll("Group A: ", "Group A:<br/>");
//        	}
//        	if(!("".equals(teamA) || "".equals(teamB))) {
        		dbp.updateCricLiveScore(teamA, teamB, liveScore);
//        	}
            
        } catch(Exception e) {
			log.error("", e);
        } finally {
        }
        log.debug ("*****CricLiveScoreParser END*****");
    }

}
